<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>系统架构 | 美的楼宇科技研究院</title>
    <meta name="generator" content="VuePress 1.9.5">
    <link rel="icon" href="/img/favicon.ico">
    <meta name="description" content="iBUILDING作为智慧建筑的数字践行者，致力于用数字的眼光建筑世界。以科技赋能楼宇，构建数字建筑生态，共创更美好的智慧空间。Make iBUILDING come TRUE。">
    <meta name="keywords" content="iBUILDING,ibuilding">
    <meta name="theme-color" content="#11a8cd">
    <meta name="baidu-site-verification" content="code-j1XZ46JIBR">
    
    <link rel="preload" href="/assets/css/0.styles.af9b49f9.css" as="style"><link rel="preload" href="/assets/js/app.ffe9b366.js" as="script"><link rel="preload" href="/assets/js/2.9760a328.js" as="script"><link rel="preload" href="/assets/js/8.82830ba8.js" as="script"><link rel="prefetch" href="/assets/js/10.1ca8e9a5.js"><link rel="prefetch" href="/assets/js/11.f84ca260.js"><link rel="prefetch" href="/assets/js/12.5d62fb57.js"><link rel="prefetch" href="/assets/js/13.3fd35f26.js"><link rel="prefetch" href="/assets/js/14.d428d44b.js"><link rel="prefetch" href="/assets/js/15.752b1e82.js"><link rel="prefetch" href="/assets/js/16.f33da816.js"><link rel="prefetch" href="/assets/js/17.4a25f92e.js"><link rel="prefetch" href="/assets/js/18.3ad538ff.js"><link rel="prefetch" href="/assets/js/19.4957cef9.js"><link rel="prefetch" href="/assets/js/20.264d8716.js"><link rel="prefetch" href="/assets/js/21.2e6c7b77.js"><link rel="prefetch" href="/assets/js/22.4abc22b5.js"><link rel="prefetch" href="/assets/js/23.52e85444.js"><link rel="prefetch" href="/assets/js/24.ae24e643.js"><link rel="prefetch" href="/assets/js/25.5596a9ad.js"><link rel="prefetch" href="/assets/js/26.d952969d.js"><link rel="prefetch" href="/assets/js/27.7711bd91.js"><link rel="prefetch" href="/assets/js/3.0b2e2ac4.js"><link rel="prefetch" href="/assets/js/4.d41f70ee.js"><link rel="prefetch" href="/assets/js/5.603be3f5.js"><link rel="prefetch" href="/assets/js/6.36f53e66.js"><link rel="prefetch" href="/assets/js/7.8566b5df.js"><link rel="prefetch" href="/assets/js/9.d949e13c.js">
    <link rel="stylesheet" href="/assets/css/0.styles.af9b49f9.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="https://static-btri.midea.com/mfs/1001/1656483801940.svg" alt="美的楼宇科技研究院" class="logo"> <span class="site-name can-hide">美的楼宇科技研究院</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="📖开源项目" class="dropdown-title"><!----> <span class="title" style="display:;">📖开源项目</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/driver-box/" class="nav-link">driver-box</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开发者社区" class="dropdown-title"><!----> <span class="title" style="display:;">开发者社区</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/about.html" class="nav-link">技术博客</a></li><li class="dropdown-item"><!----> <a href="https://openibuilding.midea.com/home" target="_blank" rel="noopener noreferrer" class="nav-link external">
  开放平台
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开源仓库" class="dropdown-title"><!----> <span class="title" style="display:;">开源仓库</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/iBUILDING-X" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><!----> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="📖开源项目" class="dropdown-title"><!----> <span class="title" style="display:;">📖开源项目</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/driver-box/" class="nav-link">driver-box</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开发者社区" class="dropdown-title"><!----> <span class="title" style="display:;">开发者社区</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/about.html" class="nav-link">技术博客</a></li><li class="dropdown-item"><!----> <a href="https://openibuilding.midea.com/home" target="_blank" rel="noopener noreferrer" class="nav-link external">
  开放平台
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开源仓库" class="dropdown-title"><!----> <span class="title" style="display:;">开源仓库</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/iBUILDING-X" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><a href="/driver-box/" class="sidebar-link">driver-box</a></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>用户手册</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/driver-box/quick_start/" class="sidebar-link">快速开始</a></li><li><a href="/driver-box/guides/config/" class="sidebar-link">配置说明</a></li><li><a href="/pages/8e66ec/" class="sidebar-link">HTTP Client 插件</a></li><li><a href="/pages/3162cd/" class="sidebar-link">HTTP Server 插件</a></li><li><a href="/pages/f8d682/" class="sidebar-link">Modbus 插件</a></li><li><a href="/pages/4fcadc/" class="sidebar-link">BACnet 插件</a></li><li><a href="/pages/417ad9/" class="sidebar-link">MQTT 插件</a></li><li><a href="/pages/312d09/" class="sidebar-link">TCP Server 插件</a></li><li><a href="/pages/28a924/" class="sidebar-link">脚本内置模块</a></li><li><a href="/pages/da9d86/" class="sidebar-link">RESTful API</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>开发者手册</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/driver-box/dev/compile_run/" class="sidebar-link">编译运行</a></li><li><a href="/driver-box/dev/release/" class="sidebar-link">发版记录</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>设计思路</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/pages/design/concept/" class="sidebar-link">相关概念</a></li><li><a href="/pages/design/structure/" aria-current="page" class="active sidebar-link">系统架构</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level2"><a href="/pages/design/structure/#接口层-interface" class="sidebar-link">接口层(interface)</a></li><li class="sidebar-sub-header level2"><a href="/pages/design/structure/#核心层-core" class="sidebar-link">核心层(core)</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/design/structure/#配置-config" class="sidebar-link">配置(config)</a></li><li class="sidebar-sub-header level3"><a href="/pages/design/structure/#任务-task" class="sidebar-link">任务(task)</a></li><li class="sidebar-sub-header level3"><a href="/pages/design/structure/#影子-shadow" class="sidebar-link">影子(shadow)</a></li><li class="sidebar-sub-header level3"><a href="/pages/design/structure/#通知-notice" class="sidebar-link">通知(notice)</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/design/structure/#解析层-parser" class="sidebar-link">解析层(parser)</a></li><li class="sidebar-sub-header level2"><a href="/pages/design/structure/#插件层-plugin" class="sidebar-link">插件层(plugin)</a></li></ul></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>设备实战</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/pages/674f6d/" class="sidebar-link">厕所门把手</a></li></ul></section></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-06225672><div class="articleInfo" data-v-06225672><ul class="breadcrumbs" data-v-06225672><li data-v-06225672><a href="/" title="首页" class="iconfont icon-home router-link-active" data-v-06225672></a></li> <li data-v-06225672><span data-v-06225672>driver-box</span></li><li data-v-06225672><span data-v-06225672>设计思路</span></li></ul> <div class="info" data-v-06225672><div title="作者" class="author iconfont icon-touxiang" data-v-06225672><a href="javascript:;" data-v-06225672>爱丁</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-06225672><a href="javascript:;" data-v-06225672>2023-04-19</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-title">目录</div> <div class="right-menu-content"></div></div></div> <h1><img src="">系统架构<!----></h1> <div class="page-slot page-slot-top">
    <div class="wwads-cn wwads-horizontal page-wwads" data-id="136"></div>
    <style>
      .page-wwads{
        width:100%!important;
        min-height: 0;
        margin: 0;
      }
      .page-wwads .wwads-img img{
        width:80px!important;
      }
      .page-wwads .wwads-poweredby{
        width: 40px;
        position: absolute;
        right: 25px;
        bottom: 3px;
      }
      .wwads-content .wwads-text, .page-wwads .wwads-text{
        height: 100%;
        padding-top: 5px;
        display: block;
      }
  </style>
  </div> <div class="theme-vdoing-content content__default"><p><img src="/assets/img/structure.e76f5782.png" alt="架构图">
DriverBox整体上分为4层架构：接口层(interface)、核心层(core)、解析层(parser)和插件层(plugin)，以下将会分别阐述每一层的具体实现和作用。</p> <h2 id="接口层-interface"><a href="#接口层-interface" class="header-anchor">#</a> 接口层(interface)</h2> <p>接口层(interface)为上层应用提供统一的操作接口来实现设备点位级别的读写操作。</p> <h2 id="核心层-core"><a href="#核心层-core" class="header-anchor">#</a> 核心层(core)</h2> <p>核心层(core)主要包含了：配置(config)、任务(task)、影子(shadow)、通知(notice)这些模块。以下将分别阐述这些模块的内容。</p> <h3 id="配置-config"><a href="#配置-config" class="header-anchor">#</a> 配置(config)</h3> <p>配置模块主要负责对配置文件的处理工作。</p> <ol><li>加载配置文件</li></ol> <p>配置模块会从指定的路径目录加载所有配置文件。该路径下的每一个目录都被视为一个单独的插件的配置信息。配置模块会将它们分别读取并组合成完整的配置对象。</p> <ol start="2"><li>验证配置文件</li></ol> <p>在加载配置文件后，配置模块需要验证配置文件的正确性。这部分不仅仅包含了针对配置中每个字段的验证，同时包含了对配置文件整体完整性的验证。</p> <ol start="3"><li>解析配置文件</li></ol> <p>在验证配置文件的正确性后，配置模块会将配置文件解析成一个个方便其他模块访问的标准数据结构。</p> <ol start="4"><li>缓存配置数据</li></ol> <p>为了提高性能，配置模块需要将解析后的配置数据存储在缓存中。这样，其他模块在访问配置数据时，就不需要重新加载和解析配置文件。</p> <ol start="5"><li>提供访问接口</li></ol> <p>配置模块为其他模块提供了一套访问接口实现，使得其他模块可以方便地访问配置数据。其他模块通过这个接口，可以查询和修改配置数据。</p> <ol start="6"><li>监听配置文件变化</li></ol> <p>为了支持动态配置，配置模块需要能够监听配置文件的变化。当配置文件发生变化时，配置模块需要重新加载和解析配置文件，并更新缓存中的配置数据同时触发其他模块的更新动作。</p> <p>配置的具体使用可参考<a href="/driver-box/02.用户手册/01.配置说明.html">配置说明</a>。</p> <h3 id="任务-task"><a href="#任务-task" class="header-anchor">#</a> 任务(task)</h3> <p>任务模块主要是负责调度和管理配置文件中设置的每一个任务的生命周期，包括任务创建、任务监控以及任务销毁。</p> <ol><li>任务创建</li></ol> <p>通过配置内容，如执行时间、重复周期、优先级等，任务模块创建出相对应的执行任务。每个执行任务</p> <ol start="2"><li>任务监控</li></ol> <p>提供实时的任务状态监控功能，让用户可以随时了解任务的执行情况。对任务的执行时长和结果等信息进行监控。</p> <ol start="3"><li>任务销毁</li></ol> <p>统一管理任务的销毁工作，为提供使用者接口进行手动对任务的终止操作。</p> <h3 id="影子-shadow"><a href="#影子-shadow" class="header-anchor">#</a> 影子(shadow)</h3> <p>影子模块主要数据降噪以及设备在离线判断。</p> <ol><li>数据降噪</li></ol> <p>影子模块存储每个设备的点位信息。在完成数据的读操作之后，所读取的点位数据被缓存到影子模块当中，并更新点位的读取时间。当点位更新时间超出超时时间或者与影子服务中的点位值不同时，才会被写入到消息总线当中。
因此，该功能只有在启用消息总线的情况下才有效果。</p> <ol start="2"><li>在离线判断</li></ol> <p>影子模块对设备的在离线判断的主要根据是设备的点位读取结果。当点位读取失败次数达到设定阈值的时候，当前设备就会被认定为离线状态并且持续至点位的成功读取。</p> <h3 id="通知-notice"><a href="#通知-notice" class="header-anchor">#</a> 通知(notice)</h3> <p>通知模块主要负责向上层应用发送通知信息，例如影子模块判断出设备的在离线状态之后便可以通过通知模块完成事件的通知。</p> <h2 id="解析层-parser"><a href="#解析层-parser" class="header-anchor">#</a> 解析层(parser)</h2> <p>解析层(parser)负责对解析脚本的加载和调用工作。
在解析层中，解析脚本可以是不用的编程语言进行编写的，如Lua、JavaScript、Python等脚本语言（目前仅支持Lua）。每个脚本被存放在每个插件的配置目录，与配置文件同级。
解析脚本中的内容可以动态修改并生效，从而提高调试效率。
针对不同的接入协议，解析脚本的入参结构可能会有不同，这是由各个插件的实现来决定的。</p> <h2 id="插件层-plugin"><a href="#插件层-plugin" class="header-anchor">#</a> 插件层(plugin)</h2> <p>插件层(plugin)包含3个接口实现：驱动插件(plugin)、适配器(adapter)和连接器(connector)。</p> <ol><li>驱动插件(plugin)</li></ol> <p>驱动插件(plugin)接口定义了插件的初始化、连接器和适配器的获取以及插件销毁的流程。初始化过程中，驱动插件根据配置文件中的协议信息决定连接器和适配器的初始化以及对连接池的管理。</p> <ol start="2"><li>连接器(connector)</li></ol> <p>连接器(connector)是系统与设备的通讯连接。初始化过程中，驱动插件根据配置文件中的协议信息初始化每一个连接器。该接口定义了Send和Release方法，分别用于数据的南向传输以及连接器的释放动作。</p> <ol start="3"><li>适配器(adapter)</li></ol> <p>适配器(adapter)与设备无关，一共包含了2个方法：decode()与encode()。适配器的主要任务是将上层统一的数据结构与对应协议的数据结构进行相互转化。</p> <p>总体上来说，连接器和适配器从属于驱动插件。适配器承担了对不同协议的适配工作，连接器负责数据传输。南向数据通过encode方法转化成协议的合法结构在通过对应的连接器进行下发，而北向数据在接收到之后经过decode方法转化为同一的数据结构交付给上层应用。</p></div></div>  <div class="page-edit"><!----> <!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2023/04/20, 17:24:31</span></div></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/pages/design/concept/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">相关概念</div></a> <a href="/pages/674f6d/" class="page-nav-centre page-nav-centre-next"><div class="tooltip">厕所门把手</div></a></div> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/pages/design/concept/" class="prev">相关概念</a></span> <span class="next"><a href="/pages/674f6d/">厕所门把手</a>→
      </span></p></div></div></div> <!----></main></div> <div class="footer"><div class="icons"><a href="https://gitee.com/iBUILDING-X" title="Gitee" target="_blank" class="iconfont icon-gitee"></a></div> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2023-2023
    <span>iBUILDING</span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
          跟随系统
        </li><li class="iconfont icon-rijianmoshi">
          浅色模式
        </li><li class="iconfont icon-yejianmoshi">
          深色模式
        </li><li class="iconfont icon-yuedu">
          阅读模式
        </li></ul></div></div> <!----> <!----> <!----></div><div class="global-ui"></div></div>
    <script src="/assets/js/app.ffe9b366.js" defer></script><script src="/assets/js/2.9760a328.js" defer></script><script src="/assets/js/8.82830ba8.js" defer></script>
  </body>
</html>
